<script setup lang="ts">
import { inject, ref } from 'vue'

const addForm: any = {
  'patientIndex': '',
  'patientId': '',
  'patientName': '',
  'gender': 1,
  'idCard': '',
  'height': 0,
  'weight': 0,
  'age': 0,
  'referencePhysicianName': ''
}
const confirmFilterAttr = ['patientIndex', 'patientId', 'receivingImg']

const addFormNotShowKeys = ['patientIndex', 'patientId']

const { selectedPatientRef, modifiedPatientRef } = inject('patients') as any
const props = defineProps(['type'])

if (props.type === 'confirm') {
  modifiedPatientRef.value = Object.assign({}, selectedPatientRef.value)
} else if (props.type === 'add') {
  modifiedPatientRef.value = Object.assign({}, addForm)
}else if(props.type === 'emergencyAdd') {
  modifiedPatientRef.value = Object.assign({}, addForm)
}

</script>

<template>
  <el-form :model="modifiedPatientRef" label-width="auto" size="large" class="grid grid-cols-2 gap-x-2">
    <template v-for="(value,key) in modifiedPatientRef">
      <el-form-item :label="key" v-if="key.toString() === 'gender'">
        <el-radio-group v-model="modifiedPatientRef[key]">
          <el-radio :value="0">M</el-radio>
          <el-radio :value="1">F</el-radio>
          <el-radio :value="2">O</el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item :label="key" v-else-if="key.toString() === 'receivingImg'">
        <el-radio-group v-model="modifiedPatientRef[key]" :disabled="confirmFilterAttr.includes(key.toString())">
          <el-radio :value="1">有</el-radio>
          <el-radio :value="0">无</el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item v-else-if="key.toString() === 'height'" :label="key">
        <el-input v-model.number="modifiedPatientRef[key]" :disabled="confirmFilterAttr.includes(key.toString())">
          <template #append>cm</template>
        </el-input>
      </el-form-item>

      <el-form-item v-else-if="key.toString() === 'weight'" :label="key">
        <el-input v-model.number="modifiedPatientRef[key]" :disabled="confirmFilterAttr.includes(key.toString())">
          <template #append>Kg</template>
        </el-input>
      </el-form-item>

      <el-form-item v-else-if="key.toString() === 'age'" :label="key">
        <el-input v-model.number="modifiedPatientRef[key]" :disabled="confirmFilterAttr.includes(key.toString())">
        </el-input>
      </el-form-item>

      <el-form-item v-else-if="!addFormNotShowKeys.includes(key.toString())" :label="key">
        <el-input v-model="modifiedPatientRef[key]" :disabled="confirmFilterAttr.includes(key.toString())" />
      </el-form-item>
    </template>
  </el-form>
</template>

<style scoped>

</style>
